import { defineStore } from "pinia";
import { shallowRef } from "vue";
import { ApiClass, ApiClassroom } from "../../api";
import {  ref, shallowReactive } from "@vue/reactivity";



export const useClassStore = defineStore("class", () => {
const model=shallowReactive<API.Class.List>({
    cls_name:'',
    cls_dic_id_major:0,
    cls_status:0,
    begin:0,
    pageSize:3
})
  const list = shallowRef<PageResult<UI.List>>();
  const classRoomList =ref<UI.Get[]>();
  const teachList=shallowRef<UI.Staff[]>()
  const adminList=shallowRef<UI.Staff[]>()
  const jobList=shallowRef<UI.Staff[]>()
// onMounted(async()=>{
//     classRoomList.value=await ApiClassroom.get()
//   })
  const classroomListHandler = async () => {
    classRoomList.value = await ApiClassroom.get();
    return classRoomList.value;
  };
  const queryHandler = async () => {
    list.value = await ApiClass.list(model);
  };
ApiClassroom.get().then((res)=>(classRoomList.value=res))
ApiClass.category(4).then((res)=>(teachList.value=res))
ApiClass.category(5).then((res)=>(adminList.value=res))
ApiClass.category(6).then((res)=>(jobList.value=res))
  ApiClass.list(model).then((data) => {
    list.value = data;
  });
  return { list, model, queryHandler, classRoomList,classroomListHandler, teachList ,adminList,jobList};
});
